package com.aijk.web.admin.controller.openapi;

import com.aijk.ehm.api.EhmResidentApi;
import com.aijk.ehm.api.SysFeedbackApi;
import com.aijk.ehm.model.EhmResident;
import com.aijk.ehm.model.SysFeedback;
import com.aijk.web.admin.controller.openapi.entity.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.Date;

@Component
@Controller
public class FeedbackController extends ApiBaseController {

    private static final Logger logger = LoggerFactory.getLogger(FeedbackController.class);


    @Autowired
    private SysFeedbackApi sysFeedbackApi;

    @Autowired
    private EhmResidentApi ehmResidentApi;


    /**
     * 意见反馈
     * @param
     * @return
     */
    @RequestMapping(path = "app/feedback/save", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object feedback(@Valid SysFeedback sysFeedback) {
        if(StringUtils.isEmpty(sysFeedback.getRid()))
            return  new ApiResponse("-1","参数异常");

        EhmResident ehmResident = ehmResidentApi.findOne(sysFeedback.getRid());
        sysFeedback.setCompanyId(ehmResident.getCompanyId());
        sysFeedback.setMobile(ehmResident.getCellphone());
        sysFeedback.setUid(ehmResident.getUid());
        sysFeedback.setContent(sysFeedback.getContent());
        sysFeedback.setUsername(ehmResident.getTitle());
        sysFeedback.setRid(ehmResident.getId());
        sysFeedback.setCreateTime(new Date());
        sysFeedbackApi.save(sysFeedback);

        ApiResponse response = new ApiResponse();
        return response;
    }


}
